import { formatTime } from '@/utils/index.js'
import {
  getHouseStatus,
  getHouseInfoStatus,
  getCommentStatus,
  getReplyStatus,
  getAppointmentStatus,
  getOrderStatus,
  getLeaseStatus
} from '@/mixins/index'

/**
 * 使用方法：{{item.time | timeFiter('yyyy-MM-dd hh:mm:ss')}}
 */

const timeFilter = function(time, resetformat) {
  resetformat = resetformat || 'yyyy-MM-dd hh:mm:ss'
  if (time) {
    return formatTime(new Date(time), resetformat)
  }
}

const houseStatusFilter = function(val) {
  const statusList = getHouseStatus.data().houseStatusList
  for (const key in statusList) {
    if (val === statusList[key].value) {
      return statusList[key].text
    }
  }
}

const houseInfoStatusFilter = function(val) {
  const statusList = getHouseInfoStatus.data().houseInfoStatusList
  for (const key in statusList) {
    if (val === statusList[key].value) {
      return statusList[key].text
    }
  }
}

const commentStatusFilter = function(val) {
  const statusList = getCommentStatus.data().commentStatusList
  for (const key in statusList) {
    if (val === statusList[key].value) {
      return statusList[key].text
    }
  }
}

const replyStatusFilter = function(val) {
  const statusList = getReplyStatus.data().replyStatusList
  for (const key in statusList) {
    if (val === statusList[key].value) {
      return statusList[key].text
    }
  }
}

const replyTypeFilter = function(val) {
  if (val.cid) {
    return '评论回复'
  } else if (val.rid) {
    return '引用回复'
  } else {
    return '房屋回复'
  }
}

const appointmentStatusFilter = function(val) {
  const statusList = getAppointmentStatus.data().appointmentStatusList
  for (const key in statusList) {
    if (val === statusList[key].value) {
      return statusList[key].text
    }
  }
}

const orderStatusFilter = function(val) {
  const statusList = getOrderStatus.data().orderStatusList
  for (const key in statusList) {
    if (val === statusList[key].value) {
      return statusList[key].text
    }
  }
}

const leaseStatusFilter = function(val) {
  const statusList = getLeaseStatus.data().leaseStatusList
  for (const key in statusList) {
    if (val === statusList[key].value) {
      return statusList[key].text
    }
  }
}

const falseFilter = function(val) {
  if (!val) {
    return '未知'
  } else { return val }
}

export default {
  timeFilter,
  houseStatusFilter,
  houseInfoStatusFilter,
  commentStatusFilter,
  replyStatusFilter,
  replyTypeFilter,
  appointmentStatusFilter,
  orderStatusFilter,
  leaseStatusFilter,
  falseFilter
}
